package kuonjisai.swing.jdbc;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class J26_SungJukNewData extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField eng;
	private JTextField mat;
	private JTextField name;
	private JTextField kor;
	private static J26_SungJukService sjsrv;

	/**
	 * Create the dialog.
	 */
	public J26_SungJukNewData( JFrame p ) {
		super( p );
		sjsrv = new J26_SungJukService();
		setModalityType( ModalityType.DOCUMENT_MODAL );
		setTitle( "새 성적 입력"  );
		
		setBounds(100, 100, 480, 300				);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.WEST);
		GridBagLayout gbl_contentPanel = new GridBagLayout();
		gbl_contentPanel.columnWidths = new int[]{70, 60, 44, 0, 0, 0};
		gbl_contentPanel.rowHeights = new int[]{50, 0, 0, 0, 0, 0, 0};
		gbl_contentPanel.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		contentPanel.setLayout(gbl_contentPanel);
		{
			JLabel namelbl = new JLabel("이 름");
			GridBagConstraints gbc_namelbl = new GridBagConstraints();
			gbc_namelbl.insets = new Insets(0, 0, 5, 5);
			gbc_namelbl.gridx = 1;
			gbc_namelbl.gridy = 1;
			contentPanel.add(namelbl, gbc_namelbl);
		}
		{
			name = new JTextField();
			GridBagConstraints gbc_name = new GridBagConstraints();
			gbc_name.gridwidth = 2;
			gbc_name.insets = new Insets(0, 0, 5, 0);
			gbc_name.fill = GridBagConstraints.HORIZONTAL;
			gbc_name.gridx = 3;
			gbc_name.gridy = 1;
			contentPanel.add(name, gbc_name);
			name.setColumns(10);
		}
		{
			JLabel korlbl = new JLabel("국 어");
			GridBagConstraints gbc_korlbl = new GridBagConstraints();
			gbc_korlbl.insets = new Insets(0, 0, 5, 5);
			gbc_korlbl.gridx = 1;
			gbc_korlbl.gridy = 2;
			contentPanel.add(korlbl, gbc_korlbl);
		}
		{
			kor = new JTextField();
			GridBagConstraints gbc_kor = new GridBagConstraints();
			gbc_kor.gridwidth = 2;
			gbc_kor.insets = new Insets(0, 0, 5, 0);
			gbc_kor.fill = GridBagConstraints.HORIZONTAL;
			gbc_kor.gridx = 3;
			gbc_kor.gridy = 2;
			contentPanel.add(kor, gbc_kor);
			kor.setColumns(10);
		}
		{
			JLabel englbl = new JLabel("영 어");
			GridBagConstraints gbc_englbl = new GridBagConstraints();
			gbc_englbl.insets = new Insets(0, 0, 5, 5);
			gbc_englbl.gridx = 1;
			gbc_englbl.gridy = 3;
			contentPanel.add(englbl, gbc_englbl);
		}
		{
			eng = new JTextField();
			GridBagConstraints gbc_eng = new GridBagConstraints();
			gbc_eng.gridwidth = 2;
			gbc_eng.insets = new Insets(0, 0, 5, 0);
			gbc_eng.fill = GridBagConstraints.HORIZONTAL;
			gbc_eng.gridx = 3;
			gbc_eng.gridy = 3;
			contentPanel.add(eng, gbc_eng);
			eng.setColumns(10);
		}
		{
			JLabel matlbl = new JLabel("수 학");
			GridBagConstraints gbc_matlbl = new GridBagConstraints();
			gbc_matlbl.insets = new Insets(0, 0, 5, 5);
			gbc_matlbl.gridx = 1;
			gbc_matlbl.gridy = 4;
			contentPanel.add(matlbl, gbc_matlbl);
		}
		{
			mat = new JTextField();
			GridBagConstraints gbc_mat = new GridBagConstraints();
			gbc_mat.gridwidth = 2;
			gbc_mat.insets = new Insets(0, 0, 5, 0);
			gbc_mat.fill = GridBagConstraints.HORIZONTAL;
			gbc_mat.gridx = 3;
			gbc_mat.gridy = 4;
			contentPanel.add(mat, gbc_mat);
			mat.setColumns(10);
		}
		{
			JButton btnNewButton = new JButton("New button");
			GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
			gbc_btnNewButton.insets = new Insets(0, 0, 0, 5);
			gbc_btnNewButton.gridx = 3;
			gbc_btnNewButton.gridy = 5;
			contentPanel.add(btnNewButton, gbc_btnNewButton);
		}
		{
			JButton btnNewButton_1 = new JButton("New button");
			GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
			gbc_btnNewButton_1.gridx = 4;
			gbc_btnNewButton_1.gridy = 5;
			contentPanel.add(btnNewButton_1, gbc_btnNewButton_1);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				// 더블클릭하면 액션이벤트가 자동적으로 생성이 됩니다.
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						
						if ( name.getText().equals("") 
								|| kor.getText().equals("") || eng.getText().equals("") || mat.getText().equals("") ){
							JOptionPane.showMessageDialog(null, "누락된 항목이 있습니다~ ", "오류발생!!", JOptionPane.ERROR_MESSAGE );
							return;
						} 
						
						String nameval = name.getText();
						int korval =  Integer.parseInt(kor.getText());
						int engval =  Integer.parseInt(eng.getText());
						int matval =  Integer.parseInt( mat.getText() );
						String msg = nameval + " / " + korval  + " / "  +  engval + " / " + matval;
						JOptionPane.showMessageDialog(null,  msg );
						
						J26_SungJukVO sj = new J26_SungJukVO();
						sj.setName( name.getText() );
						sj.setKor( kor.getText() );
						sj.setEng( eng.getText() );
						sj.setMat( mat.getText() );
						
						if ( sjsrv.createSungJuk( sj ) ){
							JOptionPane.showMessageDialog(null, "정상적으로 처리되었습니다.");
						}
						else {
							
							JOptionPane.showMessageDialog(null, "오류 발생.", "Error", JOptionPane.ERROR_MESSAGE);
						}
						
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton =  new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
					name.setText( "" );
					kor.setText( "" );
					eng.setText( "" );
					mat.setText( "" );
					
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		
		
		setVisible(true);
	}

}
